(() => {

    'use strict';
    goog.provide('Blockly.Blocks.ruilong');
    goog.require('Blockly.Blocks');
    goog.require('path');

    const mediaDirPath = path.join(document.currentScript.src, '../../media/');

    Blockly.Msg['RUILONG_HUE'] = 120;


       //执行器-扬声器模块
    Blockly.Blocks.ruilong_speaker_tone = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("扬声器模块")
                .appendField(new Blockly.FieldImage(mediaDirPath + "/ruilong/RLSEB802SB.png", 40, 63));
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendValueInput('FREQUENCY').setCheck(Number).appendField(Blockly.Msg.MIXLY_FREQUENCY);
            this.appendValueInput('DURATION', Number).setCheck(Number).appendField(Blockly.Msg.MIXLY_DURATION).appendField("(ms)");
            this.setInputsInline(true);
            this.setPreviousStatement(true);
            this.setNextStatement(true);
        }
    };

    //执行器-扬声器停止模块
    Blockly.Blocks.ruilong_speaker_Notone = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("扬声器停止模块");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendValueInput("DELAY_TIME", Number).appendField(Blockly.Msg.MIXLY_DELAY).setCheck(Number).appendField("(ms)");
            this.setInputsInline(true);
            this.setPreviousStatement(true);
            this.setNextStatement(true);
        }
    };


  var MOUSE_KEYBOARD_LIST = [
["A", "KEY_A"],["B", "KEY_B"],["C", "KEY_C"],["D", "KEY_D"],["E", "KEY_E"],
["F", "KEY_F"],["G", "KEY_G"],["H", "KEY_H"],["I", "KEY_I"],["J", "KEY_J"],
["K", "KEY_K"],["L", "KEY_L"],["M", "KEY_M"],["N", "KEY_N"],["O", "KEY_O"],
["P", "KEY_P"],["Q", "KEY_Q"],["R", "KEY_R"],["S", "KEY_S"],["T", "KEY_T"],
["U", "KEY_U"],["V", "KEY_V"],["W", "KEY_W"],["X", "KEY_X"],["Y", "KEY_Y"],
["Z", "KEY_Z"],["1", "KEY_1"],["2", "KEY_2"],["3", "KEY_3"],["4", "KEY_4"],
["5", "KEY_5"],["6", "KEY_6"],["7", "KEY_7"],["8", "KEY_8"],["9", "KEY_9"],
["0", "KEY_0"],["↑", "KEY_UP_ARROW"],["↓", "KEY_DOWN_ARROW"],["←", "KEY_LEFT_ARROW"],["→", "KEY_RIGHT_ARROW"],
["鼠标左键", "MOUSE_LEFT"],["鼠标右键", "MOUSE_RIGHT"],["鼠标中键", "MOUSE_MIDDLE"]];

    
    Blockly.Blocks.ruilong_ch9329_mouse_keyboard = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("设置键盘鼠标模块").appendField(new Blockly.FieldImage(mediaDirPath + "/ruilong/RLSEB329CH.png", 40, 63));
            this.appendValueInput("TXPIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown(MOUSE_KEYBOARD_LIST), "MOUSE_KEYBOARD");
            this.appendDummyInput("")
                .appendField(new Blockly.FieldDropdown([["键盘按下", "KEYBOARD_PRESS"], ["键盘释放", "KEYBOARD_RELEASE"], ["键盘全释放", "KEYBOARD_RELEASE_ALL"],
                ["鼠标按下", "MOUSE_PRESS"], ["鼠标释放", "MOUSE_PRESS"], ["鼠标全释放", "MOUSE_RELEASEALL"]]), "PRESS_RELEASE");
            this.setInputsInline(true);
            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setTooltip(Blockly.Msg.MIXLY_VOLUMEChoose);


        }
    };

    //闪灯模块
    Blockly.Blocks.ruilong_lamp = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("闪灯模块");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "HIGH"], [Blockly.Msg.MIXLY_OFF, "LOW"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //LED模块
    Blockly.Blocks.ruilong_led = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("LED模块");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "HIGH"], [Blockly.Msg.MIXLY_OFF, "LOW"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //交通灯
    Blockly.Blocks.ruilong_traffic_light = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("交通灯");
            this.appendValueInput("PIN", Number).setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.MIXLY_PIN);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldDropdown([["红灯开", "1"], ["红灯灭", "0"]]), 'RGB_LED_COLOR_R')
            .appendField(new Blockly.FieldDropdown([["黄灯开", "1"], ["黄灯灭", "0"]]), 'RGB_LED_COLOR_Y')
            .appendField(new Blockly.FieldDropdown([["绿灯开", "1"], ["绿灯灭", "0"]]), 'RGB_LED_COLOR_G');
            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //蜂鸣器模块
    Blockly.Blocks.ruilong_buzzer = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("蜂鸣器模块");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "HIGH"], [Blockly.Msg.MIXLY_OFF, "LOW"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //继电器模块
    Blockly.Blocks.ruilong_relay = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("继电器模块(5V/10A)");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "LOW"], [Blockly.Msg.MIXLY_OFF, "HIGH"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //继电器模块
    Blockly.Blocks.ruilong_relay_3V = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("继电器模块(3V/3A)");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "LOW"], [Blockly.Msg.MIXLY_OFF, "HIGH"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //震动马达模块
    Blockly.Blocks.ruilong_vibrator = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("震动马达模块");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "HIGH"], [Blockly.Msg.MIXLY_OFF, "LOW"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //马达风扇模块
    Blockly.Blocks.ruilong_motor = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("马达风扇模块");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "HIGH"], [Blockly.Msg.MIXLY_OFF, "LOW"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };
    //USB电源模块
    Blockly.Blocks.ruilong_usb = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("USB电源模块");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_STAT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "HIGH"], [Blockly.Msg.MIXLY_OFF, "LOW"]]), "STAT");
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };


  })();